package NewTmas.Listeners;

import NewTmas.FramesandPanels.JobGraphPanel;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: abhatnag
 * Date: 8/18/11
 * Time: 8:17 AM
 * To change this template use File | Settings | File Templates.
 */
public class PeriodicRefreshListener implements ItemListener {
    Timer timer;
    ActionListener refreshtimer;
     int timeInterval;
      List<JobGraphPanel> graphPanels;
    String suffix;

    public PeriodicRefreshListener(ActionListener refreshtimer, int timeInterval, List<JobGraphPanel> graphPanels, String suffix) {
        this.refreshtimer=refreshtimer;
        this.timeInterval = timeInterval;
        this.graphPanels=graphPanels;
        this.suffix=suffix;
    }






    public void itemStateChanged(ItemEvent e) {

        if(e.getSource() instanceof JCheckBoxMenuItem){
            JCheckBoxMenuItem item=(JCheckBoxMenuItem )e.getSource();

            if(item .isSelected()) {
                timer=new Timer(timeInterval ,refreshtimer);
                timer.start();
            }
            else{
                timer.stop();
            }
             for(JobGraphPanel jobGraphPanel:graphPanels){

            jobGraphPanel.refreshRate.setText("Refresh Rate : "+suffix);
        }

        }
    }
}
